package com.cyzy.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class Timer {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    public void checkKeyAfterDelay(String key, long delay) {
        new Thread(() -> {
            try {
                // 等待指定的延迟时间
                Thread.sleep(delay);
                // 检查键是否存在
                if (redisTemplate.opsForValue().get(key) == null) {
                    System.out.println("不存在");
                }

            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                System.out.println("Thread interrupted: " + e.getMessage());
            }
        }).start();
    }

}
